<?php

namespace app\api\controller;

use app\api\model\Sender as BZModel;
use think\facade\Request;

class Sender extends Common
{
    /**
     * @param BZModel $model
     * @param Request $request
     * @return \think\response\Json
     */
    public function index(BZModel $model, Request $request)
    {
        $res = $model->index(
            ['name' => $request::param('name', ''), 'phone' => $request::param('phone', '')],
            $request::param('page', 1),
            $request::param('size', 10)
        );
        return is_string($res) ? $this->returnJson(500, $res) : $this->returnJson(200, 'ok', $res);
    }

    /**
     * @param BZModel $model
     * @param Request $request
     * @return \think\response\Json
     */
    public function store(BZModel $model, Request $request)
    {
        $data = $request::param();
        $res = $model->store($data);
        return is_string($res) ? $this->returnJson(500, $res) : $this->returnJson(200, 'ok', $res);
    }

    /**
     * @param $id
     * @param BZModel $model
     * @return \think\response\Json
     */
    public function show($id, BZModel $model)
    {
        $res = $model->show($id);
        return is_string($res) ? $this->returnJson(500, $res) : $this->returnJson(200, 'ok', $res);
    }

    /**
     * @param $id
     * @param BZModel $model
     * @param Request $request
     * @return \think\response\Json
     */
    public function update($id, BZModel $model, Request $request)
    {
        $data = $request::param();
        $res = $model->edit($id, $data);
        return is_string($res) ? $this->returnJson(500, $res) : $this->returnJson(200, 'ok', $res);
    }

    /**
     * @param $id
     * @param BZModel $model
     * @return \think\response\Json
     */
    public function delete($id, BZModel $model)
    {
        $res = $model->del($id);
        return is_string($res) ? $this->returnJson(500, $res) : $this->returnJson(200, 'ok', $res);
    }
}
